<?php
/**
 * Created by PhpStorm.
 * User: Jmashimaro
 * Date: 2015/4/24
 * Time: 14:15
 */
class CouponsModel extends BaseModel {

    public $table = 'coupons';

    public $prikey = 'cou_id';

    /**
     * 获取当前优惠卷的信息
     * @param $coupon_id
     * @return mixed
     * @author jyx
     * @date 2015/09/06
     */
    public function getCouponsInfo($coupon_id) {
        $sql = 'select cp.id as cpid,cp.uid,a.name as act_name,a.start_time as act_start_time,
                a.end_time as act_end_time,co.name as coupon_name,co.amount,co.start_time as co_start_time,
                co.end_time as co_end_time,a.id as aid,ap.pid
                from '.DB_PREFIX.'coupons_participate cp
                left join '.DB_PREFIX.'coupons co on cp.cid=co.id
                left join '.DB_PREFIX.'activity a on cp.aid=a.id
                left join '.DB_PREFIX."activity_product ap on ap.aid=a.id
                where cp.id={$coupon_id} and cp.status=0 and co.status=1 and a.status=1 LIMIT 1";
        return $this->getRow($sql);
    }

}